﻿using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace SignalRTest.Controllers
{
    public class User1Controller : Controller
    {
        [HttpGet]
        // GET: User1
        public ActionResult Login()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Login(string username,string password)
        {
            using (ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("47.106.207.95:6379,password=123456"))
            {
                IDatabase db = redis.GetDatabase();

                string sessionid = Guid.NewGuid().ToString();

                Response.SetCookie(new HttpCookie("singnalrSessionId", sessionid));

                db.StringSet("user_login_singnalrSessionId_"+sessionid, username); 
            } 

            return Redirect("/user1/chat");
        }

        [HttpGet]
        // GET: User1
        public ActionResult Chat()
        {
            return View();
        }
    }
}